package com.byt.netapi.exception;

import com.byt.netapi.bean.ResponseBean;

import io.reactivex.functions.Function;
/**
 * HandleFuc处理以下网络错误：
 * 1、应用数据的错误会抛RuntimeException；
 */
public class AppDataErrorHandler implements Function<ResponseBean,ResponseBean> {
    @Override
    public ResponseBean apply(ResponseBean response) throws Exception {
        //response中code码不会0 出现错误
        if (response instanceof ResponseBean && response.getRcode() != 200)
            throw new RuntimeException(response.getRcode() + "" + (response.getMsg() != null ? response.getMsg() : ""));
        return response;
    }
}